# -*- coding:utf-8 -*-
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None
class Solution:
    # 返回构造的TreeNode根节点
    # 参考：https://www.cnblogs.com/xinchrome/p/4905608.html
    def reConstructBinaryTree(self, pre, tin):
        # write code here
        if not len(tin):
            return None
        root = TreeNode(pre[0])
        root_loc = tin.index(pre[0])
        root.left = self.reConstructBinaryTree(pre[1:root_loc+1], tin[:root_loc])
        root.right = self.reConstructBinaryTree(pre[root_loc+1:], tin[root_loc+1:])
        return root



test = Solution()
test.reConstructBinaryTree([1,2,4,7,3,5,6],[4,7,2,15,3,8,6])